# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer, TIMESTAMP, Text, text
from sqlalchemy.orm import relationship

from flaskr.database import Base


class User(Base):
    __tablename__ = 'user'

    id = Column(Integer, primary_key=True)
    username = Column(Text, nullable=False, unique=True)
    password = Column(Text, nullable=False)


class Post(Base):
    __tablename__ = 'post'

    id = Column(Integer, primary_key=True)
    author_id = Column(ForeignKey('user.id'), nullable=False)
    created = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
    title = Column(Text, nullable=False)
    body = Column(Text, nullable=False)

    author = relationship('User')
